<template>
  <div class="app-container">
    <!-- 导航栏 -->
    <el-card style="margin-bottom: 5px; height: 40px" shadow="always" :body-style="{ padding: '0' }">
      <div style="display: flex; line-height: 37px">
        <h1
          v-for="(item, index) in navItems"
          :key="index"
          :class="{ DynamicCondition: isActive === index, spacing: index > 0 }"
          @click="clickToSwitch(index)"
          style="font-size: 15px; cursor: pointer"
        >
          {{ item }}
        </h1>
      </div>
    </el-card>
    <Find :OriginalFilter="{ static: true }" @Launchform="Launchform9" :formList="formList1" @findClicked="findData" />
    <!-- 周生产状况 -->
    <div v-show="isActive === 1" class="ProductionDynamic">
      <el-card style="margin-top: 5px" shadow="always" :body-style="{ padding: '15px' }">
        <div class="ProductionDynamicMainCardMainL">
          <div style="width: 70%">
            <h1 class="MainLeftCardH1">周生产状况</h1>
            <Table :isLoading="isLoading" :tableData="weekQueryQueryTableDate" :tableHeader="tableHeader1" :selection="false" :TableHeight="100" />
          </div>
          <div style="width: 30%; margin-left: 15px">
            <h1 class="MainLeftCardH1">
              周目标自定义<el-button style="width: 30px; height: 25px" type="primary" size="default" @click="handleCloseMateriaLKlc6">删</el-button>
              <el-button style="width: 30px; height: 25px" type="primary" size="default" @click="dialogVisible2 = true">增</el-button>
            </h1>
            <Table
              :isLoading="isLoading1"
              @inputChange="checkboxChange2"
              @currentRow="currentRowListOeder1"
              :tableData="WeeklyTargetQueryTableDate"
              :tableHeader="tableHeader2"
              :selection="false"
              :TableHeight="100"
            />
          </div>
        </div>
      </el-card>
    </div>

    <!-- 月生产状况 -->
    <div v-show="isActive === 0">
      <el-card style="margin-top: 15px" shadow="always" :body-style="{ padding: '15px' }">
        <div class="ProductionDynamicMainCardMain">
          <div>
            <h1 class="MainLeftCardH1">
              各生产单位月目标产量设定
              <el-button style="width: 30px; height: 25px" type="primary" size="default" @click="handleCloseMateriaLKlc5">删</el-button>
              <el-button style="width: 30px; height: 25px" type="primary" size="default" @click="dialogVisible1 = true">增</el-button>
            </h1>

            <Table
              :isLoading="isLoading2"
              @checkboxChange="checkboxChange"
              @currentRow="currentRowListOeder"
              @inputChange="checkboxChange1"
              :tableData="MonthlyQueryTableDateList"
              :tableHeader="tableHeader"
              :selection="false"
              :TableHeight="90"
            />
            <PageModule
              :PageData="{ total, buttonS: true, pageSizeShow: true }"
              :layout="'prev, pager'"
              @pageSizeChange="handleSizeChange5"
              @pageChange="handleCurrentChange5"
            />
          </div>
        </div>
      </el-card>
    </div>

    <!-- 人均效能状况 -->
    <div v-show="isActive === 2">
      <el-card style="margin-top: 15px" shadow="always" :body-style="{ padding: '15px' }">
        <div class="ProductionDynamicMainCardMain">
          <div style="width: 70%">
            <h1 class="MainLeftCardH1">人均效能状况</h1>
            <Table :isLoading="isLoading3" :tableData="personQueryTableDate" :tableHeader="tableHeader3" :selection="false" :TableHeight="98" />
          </div>
        </div>
      </el-card>
    </div>

    <el-dialog v-model="dialogVisible1" width="50%" class="dialog pb0">
      <Find :OriginalFilter="{ static: true }" @findClicked="findData1" @Launchform="Launchform1" :searchImg="false" :formList="formList2" />
    </el-dialog>

    <el-dialog v-model="dialogVisible2" width="50%" class="dialog pb0">
      <Find :OriginalFilter="{ static: true }" @findClicked="findData2" @Launchform="Launchform2" :searchImg="false" :formList="formList3" />
    </el-dialog>

    <el-dialog v-model="dialogVisible3" width="50%" class="dialog pb0">
      <Find :OriginalFilter="{ static: true }" @findClicked="findData5" @Launchform="Launchform5" :searchImg="false" :formList="formList5" />
      <Table
        :isLoading="isLoading4"
        @currentRow="currentRowListOeder2"
        @inputChange="checkboxChange3"
        style="width: 60%"
        :tableData="HolidayInquiryTableDate"
        :tableHeader="tableHeader5"
        :selection="false"
        :TableHeight="50"
      />
      <PageModule
        :PageData="{ total: total1, buttonS: true, pageSizeShow: true }"
        @pageSizeChange="handleSizeChange51"
        @pageChange="handleCurrentChange51"
      />
    </el-dialog>

    <el-dialog v-model="dialogVisible5" width="50%" class="dialog pb0">
      <Find :OriginalFilter="{ static: true }" @findClicked="findData6" @Launchform="Launchform6" :searchImg="false" :formList="formList6" />
      <el-button style="width: 30px; height: 25px; margin-top: 15px" type="primary" size="default" @click="dialogVisible6 = true">增</el-button>
      <Table
        :isLoading="isLoading5"
        @currentRow="currentRowListOeder3"
        class="table1"
        style="margin-top: 15px"
        @inputChange="checkboxChange6"
        :tableData="YieldQueryMethodsTableDate"
        :tableHeader="tableHeader6"
        :selection="false"
        :TableHeight="50"
      />
      <PageModule
        :PageData="{ total: total2, buttonS: true, pageSizeShow: true }"
        @pageSizeChange="handleSizeChange52"
        @pageChange="handleCurrentChange52"
      />
    </el-dialog>

    <el-dialog v-model="dialogVisible6" width="50%" class="dialog pb0">
      <Find :OriginalFilter="{ static: true }" @findClicked="findData7" @Launchform="Launchform7" :searchImg="false" :formList="formList7" />
    </el-dialog>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'ProductionTargets'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import {
  listupdate,
  DeleteYieldQuery,
  AddYieldQuery,
  YieldQuery,
  AddHolidayInquiry,
  deleteHolidayInquiry,
  HolidayInquiry,
  DeleteWeeklyTarget,
  AddWeeklyTarget,
  WeeklyTargetQuery,
  weekQuery,
  MonthlyQuery,
  deleteMonth,
  updateMonth,
  personQuery
} from '@/api/Control/FactoryControl/ProductionTargets'
import LoginWork from '@/utils/LoginWork'
import { ElMessage, ElMessageBox } from 'element-plus'

// 状态
const isLoading = ref(true)
const isLoading1 = ref(true)
const isLoading2 = ref(true)
const isLoading3 = ref(true)
const isLoading4 = ref(true)
const isLoading5 = ref(true)

const clearFormList4 = () => {
  formList6.value.forEach((item: any) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
    if (item.type === 'date') {
      item.dateValue = ''
    }
    if (item.type === 'dateSingle') {
      item.dateValue = ''
    }
  })
}

const clearFormList5 = () => {
  formList7.value.forEach((item: any) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
    if (item.type === 'dateSingle') {
      item.dateValue = ''
    }
  })
}

// 取资料
const listmonth = ref('')

const listupdateMethods = async () => {
  const result = await listupdate(listmonth.value)
  if (result.code === 200) {
    MonthlyQueryMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const checkboxChange6 = async (list: any) => {
  list.dutyHours = Number(list.dutyHours)
  list.dutyPersons = Number(list.dutyPersons)
  list.kpiQty = Number(list.kpiQty)
  list.ymQty = Number(list.ymQty)
  const result = await LoginWork.put<any, any>(
    `/bioDeptWrok/kpiPersonUp?deptType=${DeleteYieldQueryParms.value.deptType}&deptName=${DeleteYieldQueryParms.value.deptName}&dDate=${DeleteYieldQueryParms.value.dDate}`,
    list
  )
  if (result.code === 200) {
    YieldQueryMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const currentRowListOeder3 = (row: any) => {
  DeleteYieldQueryParms.value.dDate = row.ddate
  DeleteYieldQueryParms.value.deptName = row.deptName
  DeleteYieldQueryParms.value.deptType = row.deptType
}

// 删除
const DeleteYieldQueryParms = ref({
  deptType: '',
  deptName: '',
  dDate: ''
})

const handleCloseMateriaLKlc8 = () => {
  if (DeleteYieldQueryParms.value.dDate === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        DeleteYieldQueryMethods()
      })
      .catch(() => {})
  }
}

const DeleteYieldQueryMethods = async () => {
  const result = await DeleteYieldQuery(DeleteYieldQueryParms.value)
  if (result.code === 200) {
    YieldQueryMethods()
    DeleteYieldQueryParms.value.dDate = ''
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const AddYieldQueryParms = ref({
  ddate: '',
  deptName: '',
  deptNo: '',
  deptType: '',
  dutyHours: 0,
  dutyPersons: 0,
  factoryDept: '',
  kpiQty: 0,
  ymQty: 0
})

const Launchform7 = (row: any) => {
  AddYieldQueryParms.value.deptType = row[0].selectValue
  AddYieldQueryParms.value.factoryDept = row[1].inputValue
  AddYieldQueryParms.value.deptName = row[2].selectValue
  AddYieldQueryParms.value.deptNo = row[2].selectValue
  AddYieldQueryParms.value.ddate = row[3].dateValue
  AddYieldQueryParms.value.ymQty = Number(row[4].inputValue)
  AddYieldQueryParms.value.kpiQty = Number(row[5].inputValue)
  AddYieldQueryParms.value.dutyHours = Number(row[6].inputValue)
  AddYieldQueryParms.value.dutyPersons = Number(row[7].inputValue)
}

const findData7 = (row: any) => {
  switch (row) {
    case '保存': {
      AddYieldQueryMethods()
      break
    }
    case '置空': {
      clearFormList5()
      break
    }
  }
}

const AddYieldQueryMethods = async () => {
  const result = await AddYieldQuery(AddYieldQueryParms.value)
  if (result.code === 200) {
    YieldQueryMethods()
    clearFormList5()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const dialogVisible6 = ref(false)

const findData6 = (count: string) => {
  switch (count) {
    case '删除': {
      handleCloseMateriaLKlc8()
      break
    }
    case '置空': {
      clearFormList4()
      break
    }
  }
}

const formList7 = ref([
  {
    type: 'select',
    selectValue: '',
    selectP: '部门类别',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '成型',
        optionLabel: '成型'
      },
      {
        optionKey: '2',
        optionValue: '针车',
        optionLabel: '针车'
      },
      {
        optionKey: '2',
        optionValue: '裁断',
        optionLabel: '裁断'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '请输入部门',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '组别&线别',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '成4',
        optionLabel: '成4'
      },
      {
        optionKey: '2',
        optionValue: '成1',
        optionLabel: '成1'
      },
      {
        optionKey: '2',
        optionValue: '成5',
        optionLabel: '成5'
      },
      {
        optionKey: '2',
        optionValue: '成3',
        optionLabel: '成3'
      },
      {
        optionKey: '2',
        optionValue: '成2',
        optionLabel: '成2'
      }
    ]
  },
  {
    type: 'dateSingle',
    dateLabel: '日期',
    dateValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入月目标产量',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入日目标产量',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入出勤工时',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入出勤人数',
    inputValue: '',
    inputLabel: ''
  },

  {
    type: 'button',
    checkboxLabel: '保存'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const dialogVisible5 = ref(false)

const YieldQueryParms = ref({
  ddateEnd: '',
  ddateStart: '',
  deptName: '',
  deptType: '',
  factoryDept: '',
  pageNum: 1,
  pageSize: 40
})

const Launchform6 = (row: any) => {
  YieldQueryParms.value.ddateEnd = row[6].dateValue[1]
  YieldQueryParms.value.ddateStart = row[6].dateValue[0]
  YieldQueryParms.value.factoryDept = row[4].selectValue
  YieldQueryParms.value.deptType = row[3].selectValue
  YieldQueryParms.value.deptName = row[5].selectValue
  YieldQueryMethods()
}

const YieldQueryMethodsTableDate = ref([])

const YieldQueryMethods = async () => {
  const result = await YieldQuery(YieldQueryParms.value)
  YieldQueryMethodsTableDate.value = result.dtos.map((itam: any) => {
    itam.change = 'Y'
    itam.disableConfirm = true
    return itam
  })
  total2.value = result.total
  isLoading5.value = false
}

const total2 = ref(0)

const handleSizeChange52 = (val: number) => {
  YieldQueryParms.value.pageSize = val
  YieldQueryMethods()
}

const handleCurrentChange52 = (val: number) => {
  YieldQueryParms.value.pageNum = val
  YieldQueryMethods()
}

const formList6 = ref([
  {
    type: 'select',
    selectValue: '',
    selectP: '部门类别',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '成型',
        optionLabel: '成型'
      },
      {
        optionKey: '2',
        optionValue: '针车',
        optionLabel: '针车'
      },
      {
        optionKey: '2',
        optionValue: '裁断',
        optionLabel: '裁断'
      }
    ]
  },
  {
    type: 'dateSingle',
    dateLabel: '日期',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '插入数据'
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '部门类别',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '成型',
        optionLabel: '成型'
      },
      {
        optionKey: '2',
        optionValue: '针车',
        optionLabel: '针车'
      },
      {
        optionKey: '2',
        optionValue: '裁断',
        optionLabel: '裁断'
      }
    ]
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '部门',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '成4',
        optionLabel: '成4'
      },
      {
        optionKey: '2',
        optionValue: '成1',
        optionLabel: '成1'
      },
      {
        optionKey: '2',
        optionValue: '成5',
        optionLabel: '成5'
      },
      {
        optionKey: '2',
        optionValue: '成3',
        optionLabel: '成3'
      },
      {
        optionKey: '2',
        optionValue: '成2',
        optionLabel: '成2'
      }
    ]
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '组别',
    selectLabel: '',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '成4',
        optionLabel: '成4'
      },
      {
        optionKey: '2',
        optionValue: '成1',
        optionLabel: '成1'
      },
      {
        optionKey: '2',
        optionValue: '成5',
        optionLabel: '成5'
      },
      {
        optionKey: '2',
        optionValue: '成3',
        optionLabel: '成3'
      },
      {
        optionKey: '2',
        optionValue: '成2',
        optionLabel: '成2'
      }
    ]
  },
  {
    type: 'date',
    dateLabel: '日期',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

// 放假新增
const AddHolidayInquiryMethods = async () => {
  const result = await AddHolidayInquiry(dDateOldList2.value)
  if (result.code === 200) {
    HolidayInquiryMethods()
    formList5.value[0].dateValue = ''
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const dDateOldList2 = ref('')

const Launchform5 = (row: any) => {
  dDateOldList2.value = row[0].dateValue
}

const findData5 = (count: string) => {
  switch (count) {
    case '删除': {
      handleCloseMateriaLKlc7()
      break
    }
    case '新增': {
      if (dDateOldList2.value === '') {
        JMessage.warning('请选择正确的日期')
      } else {
        AddHolidayInquiryMethods()
      }
      break
    }
  }
}

const deleteHolidayInquiryMethods = async () => {
  const result = await deleteHolidayInquiry(dDateOldList.value)
  if (result.code === 200) {
    HolidayInquiryMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc7 = () => {
  if (dDateOldList.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deleteHolidayInquiryMethods()
      })
      .catch(() => {})
  }
}

// 放假日查询
const dialogVisible3 = ref(false)

const formList5 = ref([
  {
    type: 'dateSingle',
    dateLabel: '日期',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '新增'
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const currentRowListOeder2 = (row: any) => {
  dDateOldList.value = row.month
}

const dDateOldList = ref('')

const checkboxChange3 = async (list: any) => {
  const result = await LoginWork.post<any, any>(`/bioDeptWrok/MonthHolidayUp?dDate=${dDateOldList.value}&dDateOld=${list.month}`)
  if (result.code === 200) {
    HolidayInquiryMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const HolidayInquiryParms = ref({
  pageNum: 1,
  pageSize: 40
})

const total1 = ref(0)

const handleSizeChange51 = (val: number) => {
  HolidayInquiryParms.value.pageSize = val
  HolidayInquiryMethods()
}

const handleCurrentChange51 = (val: number) => {
  HolidayInquiryParms.value.pageNum = val
  HolidayInquiryMethods()
}

const monthList = ref('2023-01-01')

const HolidayInquiryTableDate = ref([])

const HolidayInquiryMethods = async () => {
  const result = await HolidayInquiry(monthList.value, HolidayInquiryParms.value)
  HolidayInquiryTableDate.value = result.dtos.map((item: any) => {
    return { month: item }
  })
  HolidayInquiryTableDate.value.map((item: any) => {
    item.change = 'Y'
    item.disableConfirm = true
    return item
  })

  total1.value = result.total
  isLoading4.value = false
}

// 周删除
const DeleteWeeklyTargetParms = ref({
  deptName: '',
  weekTargetQty: -1
})

const checkboxChange2 = async (list: any) => {
  list.weekTargetQty = Number(list.weekTargetQty)
  const result = await LoginWork.post<any, any>(
    `/bioDeptWrok/proTarDefUpdate?deptNameOld=${DeleteWeeklyTargetParms.value.deptName}&weekTargetQtyOld=${String(
      DeleteWeeklyTargetParms.value.weekTargetQty
    )}`,
    list
  )
  if (result.code === 200) {
    WeeklyTargetQueryMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const currentRowListOeder1 = (row: any) => {
  DeleteWeeklyTargetParms.value.deptName = row.deptName
  DeleteWeeklyTargetParms.value.weekTargetQty = row.weekTargetQty
}

const DeleteWeeklyTargetMethods = async () => {
  const result = await DeleteWeeklyTarget(DeleteWeeklyTargetParms.value)
  if (result.code === 200) {
    WeeklyTargetQueryMethods()
    DeleteWeeklyTargetParms.value.weekTargetQty = -1
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc6 = () => {
  if (DeleteWeeklyTargetParms.value.weekTargetQty === -1) {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        DeleteWeeklyTargetMethods()
      })
      .catch(() => {})
  }
}

// 周新增
const dialogVisible2 = ref(false)

const formList3 = ref([
  {
    type: 'input',
    inputPlaceholder: '部门名称',
    inputValue: ''
  },

  {
    type: 'input',
    inputPlaceholder: '目标数量',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '保存'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

const AddWeeklyTargetMethodsParms = ref({
  deptName: '',
  weekTargetQty: -1
})

const Launchform2 = (row: any) => {
  AddWeeklyTargetMethodsParms.value.deptName = row[0].inputValue
  AddWeeklyTargetMethodsParms.value.weekTargetQty = Number(row[1].inputValue)
}

const findData2 = (row: any) => {
  switch (row) {
    case '保存': {
      if (AddWeeklyTargetMethodsParms.value.deptName === '' || AddWeeklyTargetMethodsParms.value.weekTargetQty === -1) {
        JMessage.warning('部门名称和目标数量不可为空')
      } else {
        AddWeeklyTargetMethods()
      }
      break
    }
    case '置空': {
      clearFormList2()
      break
    }
  }
}

const clearFormList2 = () => {
  formList3.value.forEach((item: any) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
  })
}

const AddWeeklyTargetMethods = async () => {
  const result = await AddWeeklyTarget(AddWeeklyTargetMethodsParms.value)
  if (result.code === 200) {
    WeeklyTargetQueryMethods()
    dialogVisible2.value = false
    AddWeeklyTargetMethodsParms.value.weekTargetQty = -1
    clearFormList2()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 周目标自定义查询
const WeeklyTargetQueryTableDate = ref([])

const WeeklyTargetQueryMethods = async () => {
  const result = await WeeklyTargetQuery()
  WeeklyTargetQueryTableDate.value = result.map((item: any) => {
    item.change = 'Y'
    item.disableConfirm = true
    return item
  })
  isLoading1.value = false
}

// 周查询
const weekQueryQueryTableDate = ref([])

const weekQueryQueryMethods = async () => {
  const result = await weekQuery()

  weekQueryQueryTableDate.value = result
  isLoading.value = false
}

// 人均查询
const personQueryTableDate = ref([])

const personQueryMethods = async () => {
  const result = await personQuery()
  personQueryTableDate.value = result
  isLoading3.value = false
}

// 月增
const dialogVisible1 = ref(false)

const clearFormList1 = () => {
  formList2.value.forEach((item: any) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'checkbox') {
      item.checked = false
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
  })
}

const findData1 = (row: any) => {
  switch (row) {
    case '保存': {
      if (updateMonthParms.value.month === '' || updateMonthParms.value.seqNo === -1) {
        JMessage.warning('月份和序号不可为空')
      } else {
        updateMonthMethods()
      }
      break
    }
    case '置空': {
      clearFormList1()
      break
    }
  }
}

// 新增
const updateMonthParms = ref({
  deptFlag: '',
  deptName: '',
  deptNo: '',
  deptType: '',
  dutyPerson: '',
  levelCode: 0,
  month: '',
  monthTarget: 0,
  parentDept: '',
  seqNo: -1,
  workDays: 0
})

const updateMonthMethods = async () => {
  const result = await updateMonth(updateMonthParms.value)
  if (result.code === 200) {
    MonthlyQueryMethods()
    dialogVisible1.value = false
    updateMonthParms.value.seqNo = -1
    clearFormList1()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const Launchform1 = (row: any) => {
  updateMonthParms.value.month = row[0].inputValue
  updateMonthParms.value.seqNo = Number(row[1].inputValue)
  updateMonthParms.value.deptType = row[2].selectValue
  updateMonthParms.value.deptNo = row[3].inputValue
  updateMonthParms.value.dutyPerson = row[4].inputValue
  updateMonthParms.value.deptFlag = row[6].checked === true ? 'Y' : ''
  updateMonthParms.value.levelCode = Number(row[7].inputValue)
  updateMonthParms.value.monthTarget = Number(row[8].inputValue)
  updateMonthParms.value.parentDept = row[9].inputValue
  updateMonthParms.value.workDays = Number(row[10].inputValue)
  updateMonthParms.value.deptName = row[5].inputValue
}

const formList2 = ref([
  {
    type: 'input',
    inputPlaceholder: '月份',
    inputValue: ''
  },

  {
    type: 'input',
    inputPlaceholder: '序号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [
      { optionKey: 1, optionValue: '冲裁', optionLabel: '冲裁' },
      { optionKey: 2, optionValue: '高频', optionLabel: '高频' },
      { optionKey: 3, optionValue: '配套', optionLabel: '配套' },
      { optionKey: 4, optionValue: '针车', optionLabel: '针车' },
      { optionKey: 5, optionValue: '成型', optionLabel: '成型' }
    ],
    selectP: '部门类型'
  },
  {
    type: 'input',
    inputPlaceholder: '部门ID',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '责任人',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '部门名称',
    inputValue: ''
  },
  {
    type: 'checkbox',
    checkboxLabel: '汇总部门',
    checked: false
  },
  {
    type: 'input',
    inputPlaceholder: '汇总层级',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '本月目标产量',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '汇总部门',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '工作天数',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '保存'
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])

// 月删除
const DeleteReplenishmentMethods = async () => {
  const result = await deleteMonth(monthOldList.value, seqNoOldList.value)
  if (result.code === 200) {
    MonthlyQueryMethods()
    monthOldList.value = ''
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const handleCloseMateriaLKlc5 = () => {
  if (monthOldList.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        DeleteReplenishmentMethods()
      })
      .catch(() => {})
  }
}

const currentRowListOeder = (list: any) => {
  monthOldList.value = list.month
  seqNoOldList.value = list.seqNo
}

const seqNoOldList = ref('')
const monthOldList = ref('')

const checkboxChange = (row: any, list: any) => {
  checkboxChange1(list)
}

const checkboxChange1 = async (list: any) => {
  list.deptFlag = list.deptFlag === true ? 'Y' : 'N'

  list.seqNo = Number(list.seqNo)
  const result = await LoginWork.put<any, any>(`/bioDeptWrok/prodMonthUp?monthOld=${monthOldList.value}&seqNoOld=${seqNoOldList.value}`, list)
  if (result.code === 200) {
    MonthlyQueryMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const Launchform9 = (row: any) => {
  if (isActive.value === 0) {
    monthParms.value = row[2].dateValue === '' ? monthParms.value : row[2].dateValue
    deptFlagParms.value = row[1].checked === true ? 'N' : ''
    MonthlyQueryMethods()
  }
}

// 月查询
const MonthlyQueryMethodsParms = ref({
  pageNum: 1,
  pageSize: 40
})

const monthParms = ref('2023-03-01')

const deptFlagParms = ref('')

const MonthlyQueryTableDateList = ref([])

const MonthlyQueryMethods = async () => {
  const result = await MonthlyQuery(monthParms.value, deptFlagParms.value, MonthlyQueryMethodsParms.value)
  MonthlyQueryTableDateList.value = result.dtos.map((item: any) => {
    if (item.deptFlag) {
      item.deptFlag = true
    }
    item.change = 'Y'
    item.disableConfirm = true
    return item
  })
  total.value = result.total
  isLoading2.value = false
}

onMounted(() => {
  MonthlyQueryMethods()
})

const total = ref(0)

const handleSizeChange5 = (val: number) => {
  MonthlyQueryMethodsParms.value.pageSize = val
  MonthlyQueryMethods()
}

const handleCurrentChange5 = (val: number) => {
  MonthlyQueryMethodsParms.value.pageNum = val
  MonthlyQueryMethods()
}

// 导航栏
const navItems = ref(['月生产状况', '周生产状况', '人均效能状况'])

// 导航栏状态
const isActive = ref(0)

const formList1 = ref([
  {
    type: 'button',
    checkboxLabel: '取上月设定资料'
  },
  {
    type: 'checkbox',
    checkboxLabel: '显示明显组别',
    checked: false
  },
  {
    type: 'dateSingle',
    dateLabel: '日期',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '取资料'
  },
  {
    type: 'button',
    checkboxLabel: '目标产量/人数定义'
  },
  {
    type: 'button',
    checkboxLabel: '导出生产报表'
  },
  {
    type: 'button',
    checkboxLabel: '设置放假日期'
  },
  {
    type: 'button',
    checkboxLabel: '更新汇总部门目标产量'
  }
])

const findData = (cont: string) => {
  switch (cont) {
    case '设置放假日期': {
      dialogVisible3.value = true
      HolidayInquiryMethods()
      break
    }
    case '目标产量/人数定义': {
      dialogVisible5.value = true
      YieldQueryMethods()
      break
    }
    case '取资料': {
      listupdateMethods()
      break
    }
  }
}

// 表格数据

const tableHeader = ref([
  {
    label: '月份',
    prop: 'month'
  },
  {
    label: '序号',
    prop: 'seqNo'
  },
  {
    label: '部门类型',
    prop: 'deptType'
  },
  {
    label: '部门代码',
    prop: 'deptNo'
  },
  {
    label: '部门名称',
    prop: 'deptName'
  },
  {
    label: '责任人',
    prop: 'dutyPerson'
  },
  {
    label: '汇总部门',
    type: 'checkbox',
    prop: 'deptFlag'
  },
  {
    label: '汇总层级',
    prop: 'levelCode'
  },
  {
    label: '汇总部门',
    prop: 'parentDept'
  },
  {
    label: '本月目标产量',
    prop: 'monthTarget'
  },
  {
    label: '本月工作天数',
    prop: 'workDays'
  },
  {
    label: '当日目标产量',
    prop: 'dProdQty'
  },
  {
    label: '当日实际完成',
    prop: 'dProdQty'
  },
  {
    label: '本月累计完成',
    prop: 'mProdQty'
  },
  {
    label: '本月欠数',
    prop: 'mUnprodQty'
  },
  {
    label: '日需完成',
    prop: 'dNeedProdQty'
  },
  {
    label: '月达成率',
    prop: 'shape'
  }
])

// 表格数据

const tableHeader1 = ref([
  {
    label: '',
    prop: 'deptName'
  },
  {
    label: '',
    prop: 'seqNo'
  },
  {
    label: '',
    prop: 'itemName'
  },
  {
    label: '',
    prop: 'day1'
  },
  {
    label: '',
    prop: 'day2'
  },
  {
    label: '',
    prop: 'day3'
  },
  {
    label: '',
    prop: 'day4'
  },
  {
    label: '',
    prop: 'day5'
  },
  {
    label: '',
    prop: 'day6'
  },
  {
    label: '',
    prop: 'day7'
  },
  {
    label: '',
    prop: 'weekTtl'
  },
  {
    label: '',
    prop: 'weekTtl'
  }
])

const tableHeader5 = ref([
  {
    label: '放假日期',
    prop: 'month'
  }
])

const tableHeader6 = ref([
  {
    label: '部门类别',
    prop: 'deptType',
    change: true
  },
  {
    label: '部门',
    prop: 'factoryDept',
    change: true
  },
  {
    label: '组别&线别',
    prop: 'deptName',
    change: true
  },
  {
    label: '日期',
    prop: 'ddate',
    change: true
  },
  {
    label: '月目标产量',
    prop: 'ymQty'
  },
  {
    label: '日目标产量',
    prop: 'kpiQty'
  },
  {
    label: '出勤工时',
    prop: 'dutyHours'
  },
  {
    label: '出勤人数',
    prop: 'dutyPersons'
  }
])

const tableHeader2 = ref([
  {
    label: '部门名称',
    prop: 'deptName'
  },
  {
    label: '周目标产量',
    prop: 'weekTargetQty'
  }
])

const tableHeader3 = ref([
  {
    label: '部门',
    prop: 'deptName'
  },
  {
    label: '当日人数',
    prop: 'dayPersons'
  },
  {
    label: '当日产出/投量',
    prop: 'dayProdQty'
  },
  {
    label: '当日入库数量',
    prop: 'dayInQty'
  },
  {
    label: '当日人均产量',
    prop: 'dayPpd'
  },
  {
    label: '当月产量',
    prop: 'monthProdQty'
  },
  {
    label: '当月人均达成率',
    prop: 'monthPpd'
  }
])

//点击切换
const clickToSwitch = (index: number) => {
  if (index === 2) {
    personQueryMethods()
  }
  if (index === 1) {
    weekQueryQueryMethods()
    WeeklyTargetQueryMethods()
  }
  isActive.value = index
}
</script>

<style lang="less" scoped>
.H1Size {
  font-size: 16px;
}

.bottom {
  float: right;
}

.DynamicCondition {
  color: #f89027;
  border-bottom: 2px solid #f89027;
}

.spacing {
  margin-left: 15px;
  /* 根据需要调整间距大小 */
}

// 底部
.bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 40px;
  width: 100%;

  .total {
    font-size: 14px;
    color: rgba(0, 0, 0, 0.6);
    font-family: PingFangSC-Regular-, PingFangSC-Regular;
  }

  :deep(.el-input__wrapper) {
    padding: 0;
  }

  :deep(.el-input__suffix) {
    transform: translateX(-9px);
  }

  :deep(.el-pagination .el-select .el-input) {
    width: 88px;
  }

  :deep(.number) {
    border: 1px solid #dcdcdc;
    margin-right: 8px;
    border-radius: 3px 3px 3px 3px;
  }

  :deep(.is-active.number) {
    background-color: #f89027 !important;
    color: white;
    border-radius: 3px 3px 3px 3px;
  }
}

.ProductionDynamicMainCardMainL {
  display: flex;
}

.save {
  color: black;
  border: 1px solid #e7e7e7;
  background: #e7e7e7;
}

.MainLeftCardH1 {
  font-size: 17px;
}

.table1 {
  :deep(th:nth-child(8)) {
    color: blue !important;
  }

  :deep(th:nth-child(6)) {
    color: blue !important;
  }

  :deep(th:nth-child(5)) {
    color: blue !important;
  }

  :deep(th:nth-child(7)) {
    color: blue !important;
  }
}
</style>
